****************
*** PANEL A ****
****************
clear all
set more off

cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_version_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 == 1 & year > 1988) 
keep if classer == 1 | classer == 2 

collapse (mean) logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsarank using $folder/msa_controls_may-org.dta, nogenerate
xtset smsarank year
drop if smsarank == 26

global smsa 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 36 38 42 44 45 46 48 49 57
global controls low_skilled hisp manuf

tempname resmat
tempname effect
foreach i of global smsa {
	synth logearnwke $controls, trunit(`i') trperiod(1980) nested
	matrix `resmat' = nullmat(`resmat') \ e(RMSPE)
	matrix `effect' = nullmat(`effect'), (e(Y_treated)-e(Y_synthetic)) 
	local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE"
mat rownames `resmat' = `names'
mat colnames `effect' = "Treatment Effect"
matlist `resmat', row("Treated Unit")
matlist `effect', row("Year")
svmat `resmat', names(rmspe)
svmat `effect', names(te)

keep rmspe1 te* year
drop if rmspe1 == .
replace year = . if te1 == .
rename rmspe1 rmspe
gen n = _n
saveold fig7a.dta, replace

* NEED TO ADD TREATMENT EFFECT FOR MIAMI SEPARATELY 

****************
*** PANEL B ****
****************
clear all
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_version_figures"
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

collapse (mean) loguearnhre [pw=earnwt], by(year smsarank)
merge 1:1 year smsarank using $folder/msa_controls_may-org.dta, nogenerate
xtset smsarank year
drop if smsarank == 26

global smsa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 31 32 33 34 36 38 42 44 45 46 48 49 53 57
global controls low_skilled hisp manuf

tempname resmat
tempname effect
foreach i of global smsa {
	synth loguearnhre $controls, trunit(`i') trperiod(1980) nested
	matrix `resmat' = nullmat(`resmat') \ e(RMSPE)
	matrix `effect' = nullmat(`effect'), (e(Y_treated)-e(Y_synthetic)) 
	local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE"
matlist `resmat', row("Treated Unit")
matlist `effect', row("Year")
svmat `resmat', names(rmspe)
svmat `effect', names(te)

keep rmspe1 te* year
drop if rmspe1 == .
replace year = . if te1 == .
rename rmspe1 rmspe
gen n = _n
saveold fig7b.dta, replace

* NEED TO ADD TREATMENT EFFECT FOR MIAMI SEPARATELY 

****************
*** PANEL C ****
****************
clear all
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_version_figures"
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

collapse (p15) p15logearnwke=logearnwke [pw=earnwt], by(year smsarank)
merge 1:1 year smsarank using $folder/msa_controls_may-org.dta, nogenerate
xtset smsarank year
drop if smsarank == 26

global smsa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 36 38 42 44 45 46 49 53 57
global controls p15logearnwke(1979) p15logearnwke(1977) p15logearnwke(1975) low_skilled hisp manuf

tempname resmat
tempname effect
foreach i of global smsa {
	synth p15logearnwke $controls, trunit(`i') trperiod(1980) nested
	matrix `resmat' = nullmat(`resmat') \ e(RMSPE)
	matrix `effect' = nullmat(`effect'), (e(Y_treated)-e(Y_synthetic)) 
	local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE"
matlist `resmat', row("Treated Unit")
matlist `effect', row("Year")
svmat `resmat', names(rmspe)
svmat `effect', names(te)

keep rmspe1 te* year
drop if rmspe1 == .
replace year = . if te1 == .
rename rmspe1 rmspe
gen n = _n
saveold fig7c.dta, replace

* NEED TO ADD TREATMENT EFFECT FOR MIAMI SEPARATELY 

****************
*** PANEL D ****
****************
clear
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_version_figures"
use $folder/aux_may-org.dta

keep if age >= 19 & age <= 65
keep if cuban == 0
keep if low_skilled == 1
drop if (ftpt79 == 0 & year <= 1988) | (ftpt89 ==1 & year > 1988) 
keep if classer == 1 | classer == 2 

collapse (mean) unemp [pw=earnwt], by(year smsarank)
merge 1:1 year smsarank using $folder/msa_controls_may-org.dta, nogenerate
xtset smsarank year
drop if smsarank == 26

global smsa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 36 38 42 44 45 46 48 49 53 57
global controls unemp low_skilled hisp manuf

tempname resmat
tempname effect
foreach i of global smsa {
	synth unemp $controls, trunit(`i') trperiod(1980) nested
	matrix `resmat' = nullmat(`resmat') \ e(RMSPE)
	matrix `effect' = nullmat(`effect'), (e(Y_treated)-e(Y_synthetic)) 
	local names `"`names' `"`i'"'"'
}
mat colnames `resmat' = "RMSPE"
matlist `resmat', row("Treated Unit")
matlist `effect', row("Year")
svmat `resmat', names(rmspe)
svmat `effect', names(te)

keep rmspe1 te* year
drop if rmspe1 == .
rename rmspe1 rmspe
gen n = _n
saveold fig7d.dta, replace

* NEED TO ADD TREATMENT EFFECT FOR MIAMI SEPARATELY 
